package com.example.wanbaqian.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.example.wanbaqian.R;
import com.example.wanbaqian.base.BaseActivity;
import com.example.wanbaqian.config.CommonValue;
import com.example.wanbaqian.base.HttpCallback;
import com.example.wanbaqian.config.HttpURL;
import com.example.wanbaqian.bean.Info;
import com.example.wanbaqian.bean.UserInfoBean;
import com.example.wanbaqian.utils.GetJsonUtils;
import com.example.wanbaqian.utils.HttpUtils;
import com.example.wanbaqian.utils.SPUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 反馈界面
 */
public class FeedbackActivity extends BaseActivity implements HttpCallback {

    @BindView(R.id.Feedback_title)
    EditText FeedbackTitle;
    @BindView(R.id.Feedback_people)
    EditText FeedbackPeople;
    @BindView(R.id.Feedback_content)
    EditText FeedbackContent;
    private UserInfoBean bean;
    String title, people, content;

    @Override
    protected int getLayout() {
        return R.layout.activity_feedback;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        setStatusBarColor(R.color.main_color);
        setToolBar("意见反馈");
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected void initDate() {
        bean = SPUtils.getUserInfo(mContext);
        FeedbackPeople.setText(bean.getLogin_mobile());
        FeedbackPeople.setKeyListener(null);


    }

    @OnClick(R.id.Feedback_creat)
    public void onClick() {
        people = FeedbackPeople.getText().toString();
        title = FeedbackTitle.getText().toString();
        content = FeedbackContent.getText().toString();
        if (!TextUtils.isEmpty(title) && !TextUtils.isEmpty(people) && !TextUtils.isEmpty(content)) {
            HttpUtils.getInstance().post(GetJsonUtils.getInstance().getRequest(HttpURL.LANMEI_FEEDBACK, mContext
                    , new String[]{"accessid", "title", "contact", "content"}
                    , new String[]{SPUtils.getAccessid(mContext), title, people, content}), mContext, null, CommonValue.REQUEST_CODE1, this);
        } else {
            showToast("请填写正确的内容");
        }
    }

    @Override
    public void onSuccess(String content, Info info, int requestCode) {
        showToast(info.getMsg());
        finish();
    }

    @Override
    public void onCacheSuccess(String content, Info info, int requestCode) {

    }

    @Override
    public void onError(Info info, int requestCode) {
        showToast(info.getMsg());
    }
}
